<template lang="">
  <div>
    <div class="form_order">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-row style="margin-bottom: 25px">
          <el-col :span="24">
            <span style="font-size: 20px" >当前订单审核流程：</span>
            <div
              v-for="(item, index) in AuditList"
              :key="item.id"
              style="display: inline; margin-left: 15px"
            >
              <span
                style="color: #e71f11; font-size: 22px"
                v-if="item.status == 1"
                >{{ index + 1 }}:{{ item.audit_name }}</span
              >
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="产品类型" prop="type">
              <el-select
                v-model="type"
                placeholder="请选择产品类型"
                style="width: 100%"
                disabled
                @change="type_change"
              >
                <el-option label="半成品" :value="2"> </el-option>
                <el-option label="成品" :value="1"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="模型" prop="modelid">
              <el-select
                v-model="ruleForm.modelid"
                placeholder="请选择产品模型"
                style="width: 100%"
                disabled
                @change="modelid_change"
              >
                <el-option
                  v-for="item in ModelList"
                  :key="item.modelid"
                  :label="item.modelname"
                  :value="item.modelid"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8"  v-if="forEachs('is_replenishment')">
           
            <el-form-item label="是否补录" :prop="required('is_replenishment')">
              <el-radio-group
                v-model="ruleForm.is_replenishment"
                :disabled="disableds"
              >
                <el-radio label="1">是</el-radio>
                <el-radio label="2">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="center" v-if="FieldList.length > 0"
          >基础属性</el-divider
        >
        <div class="list_order" v-if="FieldList.length > 0">
          <div class="lis" v-if="forEachs('serial_number')">
            <el-form-item label="流水号" :prop="required('serial_number')">
              <el-input
                v-model="ruleForm.serial_number"
                disabled
              ></el-input>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('order_number')">
            <el-form-item label="订单号" :prop="required('order_number')">
              <el-input
                v-model="ruleForm.order_number"
                disabled
              ></el-input>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('order_date')">
            <el-form-item label="下单日期" :prop="required('order_date')">
              <el-date-picker
                v-model="ruleForm.order_date"
                :disabled="disableds"
                type="date"
                format="yyyy 年 MM 月 dd 日"
                style="width: 100%"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('delivery_date')">
            <el-form-item label="交货日期" :prop="required('delivery_date')">
              <el-date-picker
                v-model="ruleForm.delivery_date"
                :disabled="disableds"
                type="date"
                format="yyyy 年 MM 月 dd 日"
                style="width: 100%"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('customer_id')">
            <el-form-item label="客户" :prop="required('customer_id')">
              <el-select
                filterable
                @change="customer_change"
                v-model="ruleForm.customer_id"
                :disabled="disableds"
                placeholder="请选择客户"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in CustomerList"
                  :key="index"
                  :label="item.customer_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('account_executive_id')">
            <el-form-item
              label="业务员"
              :prop="required('account_executive_id')"
            >
              <el-select
                filterable
                @change="account_executive_change"
                v-model="ruleForm.account_executive_id"
                :disabled="disableds"
                placeholder="请选择业务员"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in EmployeeList"
                  :key="index"
                  :label="item.company_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('emergency_procedure')">
            <el-form-item
              label="紧急程度"
              :prop="required('emergency_procedure')"
            >
              <el-radio-group
                v-model="ruleForm.emergency_procedure"
                :disabled="disableds"
              >
                <el-radio label="1">普通</el-radio>
                <el-radio label="2">紧急</el-radio>
                <el-radio label="3">十万火急</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('is_stock_up')">
            <el-form-item label="是否备货" :prop="required('is_stock_up')">
              <el-radio-group
                v-model="ruleForm.is_stock_up"
                :disabled="disableds"
              >
                <el-radio label="1">是</el-radio>
                <el-radio label="2">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
          <!-- <div
            class="lis"
            v-if="ruleForm.is_replenishment == 1 && forEachs('num')"
          >
            <el-form-item label="件数" :prop="required('num')">
              <el-input
                v-model="ruleForm.num"
                type="number"
                :disabled="disableds"
              ></el-input>
            </el-form-item>
          </div> -->
          <!-- <div
            class="lis"
            v-if="ruleForm.is_replenishment == 1 && forEachs('warehouse_id')"
          >
            <el-form-item label="仓库及货架" :prop="required('warehouse_id')">
              <el-select
                v-model="ruleForm.warehouse_id"
                :disabled="disableds"
                placeholder="请选择仓库"
                @change="select_huojiua"
                style="width: 49%"
              >
                <el-option
                  v-for="(item, index) in cangkulist"
                  :key="index"
                  :label="item.warehouse_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="ruleForm.goods_shelf_id"
                :disabled="disableds"
                placeholder="请选择货架"
                @change="select_goods_shelf"
                style="width: 50%; margin-left: 1%"
              >
                <el-option
                  v-for="(item, index) in huojialist"
                  :key="index"
                  :label="item.goods_shelf_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div> -->
         
          <div class="lis" v-if="forEachs('num')">
            <el-form-item label="订单数量" :prop="required('num')">
              <el-input-number
                v-model="ruleForm.num"
              ></el-input-number>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('receivables')">
            <el-form-item label="应收款"  :prop="required('receivables')">
              <el-input v-model="ruleForm.receivables" ></el-input>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('received')">
            <el-form-item label="已收款" :prop="required('received')">
              <el-input v-model="ruleForm.received" @input='changeValue'></el-input>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('remark')">
            <el-form-item label="备注" :prop="required('remark')">
              <el-input
                v-model="ruleForm.remark"
                type="textarea"
                :disabled="disableds"
              ></el-input>
            </el-form-item>
          </div>
        </div>
        <el-divider content-position="center" v-if="FieldList.length > 0"
          >产品属性</el-divider
        >
        <div class="list_order" v-if="FieldList.length > 0">
          <div class="lis" v-if="forEachs('product_id')">
            <el-form-item label="产品" :prop="required('product_id')">
              <el-select
                filterable
                v-model="ruleForm.product_id"
                disabled
                placeholder="请选择产品"
                style="width: 100%"
                @change="product_id_change_1"
              >
                <el-option
                  v-for="(item, index_abd) in productList_mx"
                  :key="index_abd"
                  :label="item.product_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('model_number_id')">
            <el-form-item label="型号" :prop="required('model_number_id')">
              <el-select
                filterable
                v-model="ruleForm.model_number_id"
                @change="model_number_id_change"
                placeholder="请选择型号"
                style="width: 100%"
                disabled
              >
                <el-option
                  v-for="(item, index_abc) in ModelNumberList"
                  :key="index_abc"
                  :label="item.model_number"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <!-- <div class="lis" v-if="forEachs('color_id')">
            <el-form-item label="颜色" :prop="required('color_id')">
              <el-select
                @change="yanse_change"
                filterable
                allow-create
                disabled
                v-model="ruleForm.color_id"
                placeholder="请选择颜色"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index_ab) in ColorList"
                  :key="index_ab"
                  :label="item.color"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div> -->
          <div class="lis" v-if="forEachs('specification_id')">
            <el-form-item label="规格">
              <el-select
                @change="specification_change"
                filterable
                allow-create
                disabled
                v-model="ruleForm.specification_id"
                placeholder="请选择规格"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index_a) in SpecificationList"
                  :key="index_a"
                  :label="item.specification"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis" v-if="type == 2 && is_danxuan == false">
            <el-form-item label="库存">
              <el-checkbox
                v-model="ruleForm.is_kucun"
                :true-label="1"
                :false-label="2"
                :checked="ruleForm.num < chuangban_num"
                >勾选使用库存 ( {{ kucun_num }} )</el-checkbox
              >  
            </el-form-item>
          </div>
          <div
            class="lis" v-if="forEachs('warehouse_id')"
          >
            <el-form-item label="发货仓库" :prop="required('warehouse_id')">
              <el-select
                v-model="ruleForm.warehouse_id"
                :disabled="disableds"
                placeholder="请选择仓库"
                style="width:33%"
              >
                <el-option
                  v-for="(item, index) in cangkulist"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="ruleForm.goods_shelf_id"
                :disabled="disableds"
                placeholder="请选择货架"
                @change="select_goods_shelf"
                style="width:30%; margin-left: 1%"
              >
                <el-option
                  v-for="(item, index) in huojialist"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="ruleForm.warehouse_location_id"
                :disabled="disableds"
                placeholder="请选择仓位"
                @change="select_goods_shelf"
                style="width:30%; margin-left: 1%"
              >
                <el-option
                  v-for="(item, index) in cangweilist"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <!-- <div class="lis" v-if='is_addchuangtougui'>
            <el-form-item label="是否要床头柜"
            >
              <el-checkbox-button
                v-model="ruleForm.is_chuangtougui"
                :true-label="1"
                :false-label="0"
                >添加床头柜</el-checkbox-button
              >
            </el-form-item>
          </div>
          <div class="lis" v-if='is_addchuangtou'>
            <el-form-item label="是否要床头"
            >
              <el-checkbox-button
                v-model="ruleForm.is_chuangtou"
                :true-label="1"
                :false-label="0"
                >添加床头</el-checkbox-button
              >
            </el-form-item>
          </div>
          <div class="lis" v-if='is_addchuangbian'>
            <el-form-item label="是否要床边"
            >
              <el-checkbox-button
                v-model="ruleForm.is_chuangbian"
                :true-label="1"
                :false-label="0"
                >添加床边</el-checkbox-button
              >
            </el-form-item>
          </div> -->

         

        </div>
        <el-divider content-position="center" v-if="FieldList.length > 0 && type == 1 && ban_product.length>0">半成品</el-divider>
        <div v-for="(item, index) in ban_product">
          <div class="list_orders" v-if="item.select_product[0].product_name!='床头柜' && item.select_product[0].product_name!='床头' && item.select_product[0].product_name!='床边'">
            <div class="lis">
              
                <el-select
                    v-model="item.product_id"
                    placeholder="请选择子产品"
                    clearable
                    disabled
                    style="width: 100%"
                    @change="
                      ban_product_model_number(index,item.product_id,item.select_product)
                    "
                  >
                    <el-option
                      v-for="item in item.select_product"
                      :key="item.id"
                      :label="item.product_name"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
          
            </div>
            <div class="lis">
              <el-form-item label="型号">    
                <el-select
                    v-model="item.model_number_id"
                    placeholder="请选择型号"
                    clearable
                    style="width: 100%"
                    @change="
                      ban_product_specification(index,item.model_number_id,item.ModelNumberList)
                    "
                  >
                    <el-option
                      v-for="item in item.ModelNumberList"
                      :key="item.id"
                      :label="item.model_number"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
              </el-form-item>
            </div>
            <div class="lis">
              <el-form-item label="规格">
                <el-select
                  filterable
                  clearable
                  allow-create
                  v-model="item.specification_id"
                  :disabled="disableds"
                  placeholder="请选择规格"
                  style="width: 100%"
                >
                  <el-option
                    v-for="(item, index) in item.SpecificationList"
                    :key="index"
                    :label="item.specification"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
          </div>
            <div class="lis" v-if="forEachs('warehouse_id')">
            <el-form-item label="发货仓库">
              <el-select
                v-model="item.warehouse_id"
                :disabled="disableds"
                placeholder="请选择仓库"
                style="width:30%"
                @change='ban_warehouse(index,item.warehouse_id)'
              >
                <el-option
                  v-for="(item, index) in cangkulists"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="item.goods_shelf_id"
                :disabled="disableds"
                placeholder="请选择货架"
                style="width:30%; margin-left: 1%"
                @change='ban_huojia(index,item.huojialist,item.goods_shelf_id)'
              >
                <el-option
                  v-for="(item, index) in item.huojialist"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="item.warehouse_location_id"
                :disabled="disableds"
                filterable
                placeholder="请选择仓位"
                style="width:30%; margin-left: 1%"
              >
                <el-option
                  v-for="(item, index) in item.cangweilist"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>    
            <div class="lis">
              <el-form-item label="是否使用库存">  
                <el-checkbox
                v-model="item.is_kucun"
                @change='checkbox_change(index,item.kucun_num)'
                :true-label="1"
                :false-label="2"
                >勾选使用库存 ( {{ item.kucun_num }} )</el-checkbox
              >  
              </el-form-item>
            </div> 
        </div>
      </div>
      <div v-for="(item, index) in ban_product">
          <div class="list_orders"  v-if="item.select_product[0].product_name=='床头柜'&& ruleForm.is_chuangtougui==1">
            <div class="lis">
            <el-select
                    v-model="item.product_id"
                    placeholder="请选择子产品"
                    clearable
                    disabled
                    style="width: 100%"
                    @change="
                      ban_product_model_number(index,item.product_id,item.select_product)
                    "
                  >
                    <el-option
                      v-for="item in item.select_product"
                      :key="item.id"
                      :label="item.product_name"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
            </div>
            <div class="lis">
              <el-form-item label="型号">    
                <el-select
                    v-model="item.model_number_id"
                    placeholder="请选择型号"
                    clearable
                    filterable
                    style="width: 100%" 
                    @change="
                      ban_product_specification(index,item.model_number_id,item.ModelNumberList)
                    "
                  >
                    <el-option
                      v-for="item in item.ModelNumberList"
                      :key="item.id"
                      :label="item.model_number"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
              </el-form-item>
            </div>
            <div class="lis">
              <el-form-item label="规格">
                <el-select
                  filterable
                  clearable
                  allow-create
                  v-model="item.specification_id"
                  :disabled="disableds"
                  placeholder="请选择规格"
                  style="width: 100%"
                >
                  <el-option
                    v-for="(item, index) in item.SpecificationList"
                    :key="index"
                    :label="item.specification"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
          </div>
            <div class="lis">
            <el-form-item label="发货仓库">
              <el-select
                v-model="item.warehouse_id"
                :disabled="disableds"
                placeholder="请选择仓库"
                @change='ban_warehouse(index,cangkulists,item.warehouse_id)'
                style="width:30%"
              >
                <el-option
                  v-for="(item, index) in cangkulists"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="item.goods_shelf_id"
                :disabled="disableds"
                filterable
                placeholder="请选择货架"
                @change='ban_huojia(index,item.huojialist,item.goods_shelf_id)'
                style="width:30%; margin-left: 1%"
              >
                <el-option
                  v-for="(item, index) in item.huojialist"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="item.warehouse_location_id"
                :disabled="disableds"
                filterable
                placeholder="请选择仓位"
                style="width:30%; margin-left: 1%"
              >
                <el-option
                  v-for="(item, index) in item.cangweilist"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>    
          
            <div class="lis">
              <el-form-item label="是否使用库存">  
                <el-checkbox
                v-model="item.is_kucun"
                @change='checkbox_change(index,item.kucun_num)'
                true-label="1"
                false-label="2"
                >勾选使用库存 ( {{ item.kucun_num }} )</el-checkbox
              >  
              </el-form-item>
            </div> 
            <div class="lis">
              <el-form-item label="件数">    
                <el-input-number style="width:100%"
                v-model="item.num"
                :min="1"
              ></el-input-number>
              </el-form-item>
            </div>
      </div>
      </div>
      <div v-for="(item, index) in ban_product">
          <div class="list_orders"  v-if="item.select_product[0].product_name=='床头'&& ruleForm.is_chuangtou==1">
            <div class="lis">
            <el-select
                    v-model="item.product_id"
                    placeholder="请选择子产品"
                    clearable
                    disabled
                    style="width: 100%"
                    @change="
                      ban_product_model_number(index,item.product_id,item.select_product)
                    "
                  >
                    <el-option
                      v-for="item in item.select_product"
                      :key="item.id"
                      :label="item.product_name"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
            </div>
            <div class="lis">
              <el-form-item label="型号">    
                <el-select
                    v-model="item.model_number_id"
                    placeholder="请选择型号"
                    clearable
                    filterable
                    style="width: 100%" 
                    @change="
                      ban_product_specification(index,item.model_number_id,item.ModelNumberList)
                    "
                  >
                    <el-option
                      v-for="item in item.ModelNumberList"
                      :key="item.id"
                      :label="item.model_number"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
              </el-form-item>
            </div>
            <div class="lis">
              <el-form-item label="规格">
                <el-select
                  filterable
                  clearable
                  allow-create
                  v-model="item.specification_id"
                  :disabled="disableds"
                  placeholder="请选择规格"
                  style="width: 100%"
                >
                  <el-option
                    v-for="(item, index) in item.SpecificationList"
                    :key="index"
                    :label="item.specification"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
          </div>
            <div class="lis">
            <el-form-item label="发货仓库">
              <el-select
                v-model="item.warehouse_id"
                :disabled="disableds"
                placeholder="请选择仓库"
                @change='ban_warehouse(index,cangkulists,item.warehouse_id)'
                style="width:30%"
              >
                <el-option
                  v-for="(item, index) in cangkulists"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="item.goods_shelf_id"
                :disabled="disableds"
                filterable
                placeholder="请选择货架"
                @change='ban_huojia(index,item.huojialist,item.goods_shelf_id)'
                style="width:30%; margin-left: 1%"
              >
                <el-option
                  v-for="(item, index) in item.huojialist"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="item.warehouse_location_id"
                :disabled="disableds"
                filterable
                placeholder="请选择仓位"
                style="width:30%; margin-left: 1%"
              >
                <el-option
                  v-for="(item, index) in item.cangweilist"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>    
          
            <div class="lis">
              <el-form-item label="是否使用库存">  
                <el-checkbox
                v-model="item.is_kucun"
                @change='checkbox_change(index,item.kucun_num)'
                true-label="1"
                false-label="2"
                >勾选使用库存 ( {{ item.kucun_num }} )</el-checkbox
              >  
              </el-form-item>
            </div> 
            <div class="lis">
              <el-form-item label="件数">    
                <el-input-number style="width:100%"
                v-model="item.num"
                :min="1"
              ></el-input-number>
              </el-form-item>
            </div>
      </div>
      </div>
      <div v-for="(item, index) in ban_product">
          <div class="list_orders"  v-if="item.select_product[0].product_name=='床边'&& ruleForm.is_chuangbian==1">
            <div class="lis">
            <el-select
                    v-model="item.product_id"
                    placeholder="请选择子产品"
                    clearable
                    disabled
                    style="width: 100%"
                    @change="
                      ban_product_model_number(index,item.product_id,item.select_product)
                    "
                  >
                    <el-option
                      v-for="item in item.select_product"
                      :key="item.id"
                      :label="item.product_name"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
            </div>
            <div class="lis">
              <el-form-item label="型号">    
                <el-select
                    v-model="item.model_number_id"
                    placeholder="请选择型号"
                    clearable
                    filterable
                    style="width: 100%" 
                    @change="
                      ban_product_specification(index,item.model_number_id,item.ModelNumberList)
                    "
                  >
                    <el-option
                      v-for="item in item.ModelNumberList"
                      :key="item.id"
                      :label="item.model_number"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
              </el-form-item>
            </div>
            <div class="lis">
              <el-form-item label="规格">
                <el-select
                  filterable
                  clearable
                  allow-create
                  v-model="item.specification_id"
                  :disabled="disableds"
                  placeholder="请选择规格"
                  style="width: 100%"
                >
                  <el-option
                    v-for="(item, index) in item.SpecificationList"
                    :key="index"
                    :label="item.specification"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
          </div>
            <div class="lis">
            <el-form-item label="发货仓库">
              <el-select
                v-model="item.warehouse_id"
                :disabled="disableds"
                placeholder="请选择仓库"
                @change='ban_warehouse(index,cangkulists,item.warehouse_id)'
                style="width:30%"
              >
                <el-option
                  v-for="(item, index) in cangkulists"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="item.goods_shelf_id"
                :disabled="disableds"
                filterable
                placeholder="请选择货架"
                @change='ban_huojia(index,item.huojialist,item.goods_shelf_id)'
                style="width:30%; margin-left: 1%"
              >
                <el-option
                  v-for="(item, index) in item.huojialist"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="item.warehouse_location_id"
                :disabled="disableds"
                filterable
                placeholder="请选择仓位"
                style="width:30%; margin-left: 1%"
              >
                <el-option
                  v-for="(item, index) in item.cangweilist"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>    
          
            <div class="lis">
              <el-form-item label="是否使用库存">  
                <el-checkbox
                v-model="item.is_kucun"
                @change='checkbox_change(index,item.kucun_num)'
                true-label="1"
                false-label="2"
                >勾选使用库存 ( {{ item.kucun_num }} )</el-checkbox
              >  
              </el-form-item>
            </div> 
            <div class="lis">
              <el-form-item label="件数">    
                <el-input-number style="width:100%"
                v-model="item.num"
                :min="1"
              ></el-input-number>
              </el-form-item>
            </div>
      </div>
      </div>
        <el-divider
          content-position="center"
          v-if="FieldList.length > 0 && FieldList_new.length > 0"
          >额外属性</el-divider
        >
        <div class="list_order" v-if="FieldList.length > 0">
          <div class="lis" v-for="(item, index_6) in FieldList_new" :key="index_6">
            <el-form-item :label="item.name">
              <el-input
                v-if="item.formtype == 'input'&& item.field!='spare_money'"
                v-model="item.default_value"
                type="input"
                @input="input_change(item.default_value,item.field)"
              ></el-input>
              <el-input
                v-if="item.formtype == 'input' && item.field=='spare_money'"
                v-model="item.default_value"
                type="input"
                @input="input_change(item.default_value,item.field)"
              ></el-input>
              <el-select
                v-if="item.formtype == 'select'"
                v-model="item.default_value"
                placeholder="请选择"
              >
                <el-option
                  v-for="(ite, index_7) in item.option_list"
                  :key="index_7"
                  :label="ite.option_name"
                  :value="ite.option_id"
                >
                </el-option>
              </el-select>
              <el-radio-group
                v-if="item.formtype == 'radio'"
                v-model="item.default_value"
              >
                <el-radio
                  v-for="(ite, index_8) in item.option_list"
                  :key="index_8"
                  :label="ite.option_id"
                  >{{ ite.option_name }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <div style="display:flex;justify-content:center;margin-top:30px;">
      <el-button
          type="primary"
          style="margin-right: 10px"
          v-disPrevent
          @click="submitadd('ruleForm')"
          v-permission="['caiwushenhe']"
          v-if="
            ruleForm_ss.financial_status == 2 && ruleForm_ss.material_status == 1
          "
          >通过</el-button>

        <!-- 物料按钮 -->
        <el-button
          type="primary"
          style="margin-right: 10px"
          @click="submitadd('ruleForm')"
          v-permission="['wuliaoshenhe']"
          v-if="ruleForm_ss.material_status == 2 && ruleForm_ss.info_status == 1"
          >通过</el-button>
        <!-- 订单按钮 -->
        <el-button
          type="primary"
          v-disPrevent
          style="margin-right: 10px"
          @click="submitadd('ruleForm')"
          v-permission="['dingdanshenhe']"
          v-if="ruleForm_ss.info_status == 2"
          >通过</el-button>
          <!-- 删除 -->
          <el-popconfirm
          v-disPrevent
          v-permission="['dingdanshenhe_shanchu']"
          confirm-button-text="确定"
          cancel-button-text="取消"
          icon="el-icon-info"
          icon-color="red"
          title="确定删除此订单吗？"
          @confirm="del_Order(ruleForm.id)"
        >
          <el-button  type="primary" slot="reference"
            >删除</el-button
          >
        </el-popconfirm>
    </div>
  </div>
      
    </div>
  </div>
</template>
<script>
import {
  getModelList,
  getOrderAuditList,
  getProductList,
  getProductFieldList,
  automaticGenerationOrderNumber,
  automaticGenerationSerialNumber,
  getProductColorList,
  getModelNumberList,
  getCustomerList,
  createColor,
  getSpecificationList,
  getColorList,
  getSemiListByProductId,
  getProductInfoByModelNumberId,
  getModelNumberListByProduct,
  getColorByModelNumberId,
  createOrder,
  alertOrder,
  auditOrder,
  delOrder,
  getInventoryCount,
  getWarehouseList
} from "@/api/product/index";
import { getYeWuYuanList } from "@/api/user";
export default {
  data() {
    return {
      is_addchuangtougui: false,
      is_addchuangtou: false,
      is_addchuangbian: false,
      is_danxuan: false,
      ban_product: [],
      isadd: false,
      isshow: true,
      type: "",
      disableds: false,
      disableds_product: false,
      ruleForms: {},
      ruleForm_ss: {},
      ruleForm: {
        is_chuangtougui: "",
        is_chuangtou: "",
        is_chuangbian: "",
        modelid: "",
        num: "",
        warehouse_id: "",
        goods_shelf_id: "",
        warehouse_location_id: '',
        batch_number: "",
        serial_number: "",
        order_number: "",
        order_date: "",
        delivery_date: "",
        account_executive_id: "",
        product_id: "",
        model_number_id: "",
        color_id: "",
        size: "",
        specification_id: "",
        direction: "",
        customer_id: "",
        received: "",
        emergency_procedure: "1",
        is_replenishment: "2",
        is_stock_up: "2",
        receivables: "",
        remark: "",
        is_kucun: '2',
        id: "",
        unit_price: '',
        discount: "",
        spare_money: ''
      },
      rules: {
        num: [{ required: true, message: "请输入数量", trigger: "blur" }],
        warehouse_id: [
          { required: true, message: "请选择仓库", trigger: "blur" },
        ],
        goods_shelf_id: [
          { required: true, message: "请选择货架", trigger: "blur" },
        ],
        batch_number: [
          {
            required: true,
            message: "请输入生产批号",
            trigger: "blur",
          },
        ],
        specification_id: [
          {
            required: true,
            message: "请选择规格",
            trigger: "blur",
          },
        ],
        serial_number: [
          {
            required: true,
            message: "请输入流水号",
            trigger: "blur",
          },
        ],
        order_number: [
          {
            required: true,
            message: "请输入订单号",
            trigger: "blur",
          },
        ],
        order_date: [
          {
            required: true,
            message: "请选择下单日期",
            trigger: "blur",
          },
        ],
        delivery_date: [
          {
            required: true,
            message: "请选择交货日期",
            trigger: "blur",
          },
        ],
        account_executive_id: [
          {
            required: true,
            message: "请选择员工",
            trigger: "blur",
          },
        ],
        product_id: [
          {
            required: true,
            message: "请选择产品",
            trigger: "blur",
          },
        ],
        model_number_id: [
          {
            required: true,
            message: "请选择型号",
            trigger: "blur",
          },
        ],
        color_id: [
          {
            required: true,
            message: "请选择颜色",
            trigger: "blur",
          },
        ],
        size: [
          {
            required: true,
            message: "请选择规格",
            trigger: "blur",
          },
        ],
        direction: [
          {
            required: true,
            message: "请输入产品方向",
            trigger: "blur",
          },
        ],
        customer_id: [
          {
            required: true,
            message: "请选择客户",
            trigger: "blur",
          },
        ],
        emergency_procedure: [
          {
            required: true,
            message: "请选择紧急程度",
            trigger: "blur",
          },
        ],
        is_replenishment: [
          {
            required: true,
            message: "是否补货",
            trigger: "blur",
          },
        ],
        received: [
          {
            required: true,
            message: "请输入应收款",
            trigger: "blur",
          },
        ],
        receivables: [
          {
            required: true,
            message: "请输入已收款",
            trigger: "blur",
          },
        ],
        is_stock_up: [
          {
            required: true,
            message: "是否备货",
            trigger: "blur",
          },
        ],
        receivables: [
          {
            required: true,
            message: "请输入应收款金额",
            trigger: "blur",
          },
        ],
      },
      directionList: [
        {
          name: "左",
        },
        {
          name: "右",
        },
        {
          name: "无",
        },
      ],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        },
      },
      formatterTime(row, column) {
        let data = row[column.property];
        return /\d{4}-\d{1,2}-\d{1,2}/g.exec(data);
      },
      istrue: true,
      dataList: [],
      dataLists: [],
      AuditList: [],
      ModelList: [],
      FieldList: [],
      FieldList_new: [],
      productList_mx: [],
      productList: [],
      ModelNumberList: [],
      ColorList: [],
      SpecificationList: [],
      CustomerList: [],
      EmployeeList: [],
      ModelNumberList_s1: [],
      ModelNumberList_s2: [],
      ModelNumberList_s3: [],
      order_audit_name: "",
      chuangtou_num: 0,
      chuangtougui_num: 0,
      chuangbang_num: 0,
      chuangban_num: 0,
      ruleForms: [],
      chuangtougui_id: "",
      banchengpins: "",
      kucun_num: '',
      cangkulist: [],
      huojialist: [],
      cangweilist: [],
      cangkulists: []
    };
  },
  created() {
    console.log(this.$route.query.data)

  },
  mounted() {
    this.get_OrderAuditList();
    this.getCustomer();
    this.getEmpl();
    this.getproduct();

    this.ruleForm_ss = this.$route.query.data
    this.ruleForm.modelid = this.$route.query.data.modelid
    let rows = this.$route.query.data;
    for (let i = 0; i < rows.audit_log.length; i++) {
      if (
        (rows.audit_log[i].res == 0) & (rows.audit_log[i].order_audit_name == "info_status")
      ) {
        this.order_audit_name = rows.audit_log[i].order_audit_name;
        break;
      }
      if (
        (rows.audit_log[i].res == 0) &
        (rows.audit_log[i].order_audit_name == "material_status")
      ) {
        this.order_audit_name = rows.audit_log[i].order_audit_name;
        break;
      }
      if (
        (rows.audit_log[i].res == 0) &
        (rows.audit_log[i].order_audit_name == "financial_status")
      ) {
        this.order_audit_name = rows.audit_log[i].order_audit_name;
        break;
      }
    }
  },
  watch: {
    type(newval, oldvals) {
      if (newval == 1) {
        this.get_ModelList(newval);

      }
    },
    "ruleForm.product_id"(newval, oldvals) {
      // this.get_producModel(newval)
      if (this.type == 2) {
        this.get_InventoryCount();
      }
      this.getproduct_mx(this.ruleForm.modelid).then(res => {
        if (newval == res[0].id && res[0].product_name == '软床') {
            this.is_addchuangtougui = true
            this.is_addchuangtou = true
            this.is_addchuangbian = true
          }
        res.forEach(item => {
          if (newval == item.id) {
            this.ModelNumberList = item.model_number
          }
        })
      })
    },
    "ruleForm.model_number_id"(newval, oldvals) {
      if (this.type == 2) {
        this.get_InventoryCount();
      }
      // this.getproduct_mx().then(res => {
      //   console.log(res)
      //   res.forEach(item => {
      //     if (this.ruleForm.product_id == item.id) {
      //       this.ModelNumberList = item.model_number
      //       for (let i = 0; i < this.ModelNumberList.length; i++) {
      //         if (newval == this.ModelNumberList[i].id) {
      //           if (this.istrue == false) {
      //             if (this.ModelNumberList[i].pivot.unit_price) {
      //               this.$set(this.ruleForm, "unit_price", this.ModelNumberList[i].pivot.unit_price);
      //             }
      //           }
      //           this.SpecificationList = this.ModelNumberList[i].specification
      //         }
      //       }
      //     }
      //   })
      // })
      // console.log(this.ModelNumberList)

    },
    "ruleForm.specification_id"(newval, oldvals) {
      if (this.type == 2) {
        this.get_InventoryCount();
      }
      // this.SpecificationList.forEach(item => {
      //   if (newval == item.id) {
      //     if (this.istrue == false) {
      //       if (item.pivot.unit_price) {
      //         this.$set(this.ruleForm, "unit_price", item.pivot.unit_price);
      //       }
      //     }

      //   }
      // })

    },
    // "ruleForm.color_id"(newval, oldvals) {
    //   if (this.type == 2) {
    //     this.ModelList.forEach((item) => {
    //       if (item.modelid == this.ruleForm.modelid) {
    //         this.get_InventoryCount(item.modelname);
    //       }
    //     });
    //   }
    // },
    "ruleForm.warehouse_id"(newval, oldvals) {
      if (this.type == 1) {
        this.getcangku().then(res => {
          this.cangkulist = res
          res.forEach(item => {
            if (item.id == newval) {
              this.huojialist = item.children
            }
          })
        })
      } else {
        this.get_ban_WarehouseList().then(res => {
          this.cangkulist = res
          res.forEach(item => {
            if (item.id == newval) {
              this.huojialist = item.children
            }
          })
        })
      }
      if (this.type == 2) {
        this.ModelList.forEach((item) => {
          if (item.modelid == this.ruleForm.modelid) {
            this.get_InventoryCount();
          }
        });
      }
    },
    "ruleForm.goods_shelf_id"(newval, oldvals) {

      if (newval) {
        this.huojialist.forEach(item => {
          if (item.id == newval) {
            this.cangweilist = item.children
          }
        })
        if (this.type == 2) {
          this.get_InventoryCount();
        }
      }
    },
    ban_product: {
      handler(news, olds) {
        // let arry = JSON.parse(JSON.stringify(news))
        news.forEach(item => {
          let obj = {
            product_id: item.product_id,
            model_number_id: item.model_number_id,
            // color_id: this.ruleForm.color_id,
            specification_id: item.specification_id,
            warehouse_id: item.warehouse_id,
            goods_shelf_id: item.goods_shelf_id,
            warehouse_location_id: item.warehouse_location_id,
          };

          this.cangkulists.forEach(items => {
            item.huojialist = items.children
          })

          getInventoryCount(obj).then((res) => {
            if (res.code == 200) {
              this.$set(item, 'kucun_num', res.data)
              // item.kucun_num = res.data;
            }
          });

        })
      },
      deep: true
    },
    "ruleForm.unit_price"(news, olds) {
      this.FieldList_new.forEach(item => {
        if (item.field == 'unit_price') {
          item.default_value = news
        }
      })
    },
    "ruleForm.discount"(news, olds) {
      this.FieldList_new.forEach(item => {
        if (item.field == 'discount') {
          item.default_value = news
        }
      })
    },
    "ruleForm.spare_money"(news, olds) {
      this.FieldList_new.forEach(item => {
        if (item.field == 'spare_money') {
          item.default_value = news
        }
      })
    },
    ruleForm: {
      handler(news, olds) {
        this.ruleForm.spare_money = Number(this.ruleForm.receivables) - Number(this.ruleForm.received)
      },
      deep: true
    },
    FieldList_new: {
      handler(news, olds) {
        let arry = JSON.parse(JSON.stringify(news))
        if (this.istrue == false) {
          arry.forEach(item => {
            if (item.field == 'spare_money') {
              this.ruleForm.spare_money = item.default_value
            }
            if (item.field == 'discount') {
              this.ruleForm.discount = item.default_value
            }
            if (item.field == 'unit_price') {
              this.ruleForm.unit_price = item.default_value
            }
          })
          this.ruleForm.receivables = Number(this.ruleForm.unit_price) * Number(this.ruleForm.num) - Number(this.ruleForm.discount)
          this.ruleForm.spare_money = Number(this.ruleForm.receivables) - Number(this.ruleForm.received)
        }


      },
      deep: true
    },
    'ruleForm.modelid'(newval, oldvals) {
      if (newval) {
        this.modelid_change(newval)
      }
    },
  },
  methods: {
    checkbox_change(index, val) {
      if (this.ruleForm.num > val) {
        this.ban_product[index].is_kucun = 2
        this.$message.error("库存不足，不能勾选");
      }
    },
    push_ruleForm() {
      let row = this.$route.query.data
      this.type = this.$route.query.data.pid
      this.ruleForm.num = row.num,
        this.ruleForm.modelid = row.modelid
      this.ruleForm.warehouse_id = row.warehouse_id,
        this.ruleForm.goods_shelf_id = row.goods_shelf_id,
        this.ruleForm.warehouse_location_id = row.warehouse_location_id,
        this.ruleForm.batch_number = row.batch_number,
        this.ruleForm.serial_number = row.serial_number,
        this.ruleForm.order_number = row.order_number,
        this.ruleForm.order_date = row.order_date,
        this.ruleForm.delivery_date = row.delivery_date,
        this.ruleForm.account_executive_id = row.account_executive_id,
        this.ruleForm.product_id = row.product_id,
        this.ruleForm.model_number_id = row.model_number_id,
        this.ruleForm.color_id = row.color_id,
        this.ruleForm.size = row.size,
        this.ruleForm.is_chuangtougui = row.is_chuangtougui,
        this.ruleForm.is_chuangtou = row.is_chuangtou,
        this.ruleForm.is_chuangbian = row.is_chuangbian,
        this.ruleForm.specification_id = row.specification_id,
        this.ruleForm.direction = row.direction,
        this.ruleForm.customer_id = row.customer_id,
        this.ruleForm.received = row.received,
        this.ruleForm.emergency_procedure = row.emergency_procedure,
        this.ruleForm.is_replenishment = row.is_replenishment,
        this.ruleForm.is_stock_up = row.is_stock_up,
        this.ruleForm.receivables = row.receivables,
        this.ruleForm.remark = row.remark,
        this.ruleForm.id = row.id,
        this.ruleForm.unit_price = row.models_field ? row.models_field.unit_price : '',
        this.ruleForm.discount = this.$route.query.data.models_field ? this.$route.query.data.models_field.discount : ''
      this.ruleForm.spare_money = row.models_field ? row.models_field.spare_money : ''


      this.getcangku()
      if (this.$route.query.data.pid == 1) {
        this.get_ModelList();
        let order_second = this.$route.query.data.order_second;
        order_second.forEach(item => {
          this.get_ProductList(item.warehouse_location_id, item.modelid, item.models.modelname, item.warehouse_id, item.goods_shelf_id, item.product_id, item.model_number_id, item.specification_id, item.num, item.is_kucun)
        })
        this.get_ban_WarehouseList()
      } else {
        this.get_ModelList();
        this.get_ban_WarehouseList()
        let order_second = this.$route.query.data.order_second;
        order_second.forEach(item => {
          this.$set(this.ruleForm, "is_kucun", item.is_kucun);
        })
      }

    },
    ban_huojia(index, list, val) {
      list.forEach(item => {
        if (item.id == val) {
          this.ban_product[index].cangweilist = item.children
        }
      })
    },
    ban_warehouse(index, list, id) {
      list.forEach(item => {
        if (id == item.id) {
          this.ban_product[index].huojialist = item.children
        }
      })
    },
    async get_ban_WarehouseList() {
      var arry = []
      await getWarehouseList({ warehouse_type_id: 2 }).then((res) => {
        if (res.code == 200) {
          this.cangkulists = res.data.data;
          arry = res.data.data
        }
      });
      return arry
    },
    input_change(num, type) {
      this.$forceUpdate();
      if (type == "unit_price") {
        this.$set(this.ruleForm, num, num);
      }
    },
    ban_product_model_number(index, id, list) {
      list.forEach(item => {
        if (item.id == id) {
          this.ban_product[index].ModelNumberList = item.model_number;
        }
      })
    },
    ban_product_specification(index, id, list) {
      list.forEach(item => {
        if (item.id == id) {
          this.ban_product[index].SpecificationList = item.specification;
        }
      })
    },
    //半成品
    get_InventoryCount() {
      let obj = {
        product_id: this.ruleForm.product_id,
        model_number_id: this.ruleForm.model_number_id,
        // color_id: this.ruleForm.color_id,
        specification_id: this.ruleForm.specification_id,
        warehouse_id: this.ruleForm.warehouse_id,
        goods_shelf_id: this.ruleForm.goods_shelf_id
      };
      getInventoryCount(obj).then((res) => {
        if (res.code == 200) {
          this.kucun_num = res.data;
        }
      });
    },
    get_SemiListByProductId(val) {
      this.ban_product = [];
      getProductInfoByModelNumberId({
        modelid: this.ruleForm.modelid,
        model_number_id: val,
      }).then((res) => {
        if (res.code == 200) {
          this.SemiList = res.data;
          // this.ban_product = res.data
          this.SemiList.forEach((item) => {
            getProductList({ is_dropdown: 1, modelid: item.modelid }).then(
              (res) => {
                if (res.code == 200) {

                  this.ban_product_model_numbers(res.data[0].id).then(ress => {
                    let arry = []
                    res.data.forEach(item => {
                      if (item.id == res.data[0].id) {
                        arry = item.model_number
                      }
                    })
                    let obj = {
                      modelid: item.modelid,
                      modelname: item.modelname,
                      warehouse_id: '',
                      goods_shelf_id: '',
                      huojialist: [],
                      select_product: res.data,
                      ModelNumberList: arry,
                      product_id: res.data[0].id,
                      model_number_id: "",
                      specification_id: '',
                      num: "",
                      kucun_num: '',
                      is_kucun: "2",
                    };
                    this.ban_product.push(obj);
                  })
                }
              }
            );
          });
        }
      });
    },
    push_cangwei(list, id) {
      var arry = []
      list.forEach(item => {
        if (item.id == id) {
          arry = item.children
        }
      })
      return arry
    },
    get_ProductList(warehouse_location_ids, modelids, modelnames, warehouse_ids, goods_shelf_ids, product_ids, model_number_ids, specification_ids, chuangtougui_num, is_kucuns) {
      getProductList({ is_dropdown: 1, modelid: modelids }).then((res) => {
        if (res.code == 200) {
          this.ban_product_model_numbers(res.data[0].id).then(ress => {
            this.cangkulists.forEach(item => {
              if (warehouse_ids == item.id) {
                let obj = {
                  modelid: modelids,
                  modelname: modelnames,
                  warehouse_id: warehouse_ids,
                  goods_shelf_id: goods_shelf_ids,
                  warehouse_location_id: warehouse_location_ids,
                  cangweilist: this.push_cangwei(item.children, goods_shelf_ids),
                  huojialist: item.children,
                  select_product: res.data,
                  ModelNumberList: ress,
                  product_id: product_ids,
                  model_number_id: model_number_ids,
                  specification_id: specification_ids,
                  num: chuangtougui_num,
                  is_kucun: is_kucuns,
                };
                this.ban_product.push(obj);
              }

            })

          })
        }
      });


    },
    async ban_product_model_numbers(id) {
      var arry = []
      await getModelNumberListByProduct({ product_id: id }).then((res) => {
        if (res.code == 200) {
          arry = res.data;
        }
      });
      return arry
    },
    async getcangku() {
      var arry = []
      await getWarehouseList({ warehouse_type_id: 1 }).then((res) => {
        if (res.code == 200) {
          this.cangkulist = res.data.data;
          arry = res.data.data;
        }
      });
      return arry
    },
    // 订单提交
    submitadd(formName) {
      this.$set(this.ruleForm, "pid", this.type);
      let semi_product = []
      this.ban_product.forEach(item => {
        console.log(item);
        let obj = {
          modelid: item.modelid,
          warehouse_id: item.warehouse_id,
          goods_shelf_id: item.goods_shelf_id,
          product_id: item.product_id,
          model_number_id: item.model_number_id,
          specification_id: item.specification_id,
          num: item.num,
          is_kucun: item.is_kucun,
        };
        semi_product.push(obj)
      })
      this.$set(this.ruleForm, "semi_product", semi_product);
      console.log(this.ruleForm)
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alertOrder({ order_data: this.ruleForm }).then((res) => {
            if (res.code == 200) {
              // this.isProduct = false;alert
              // this.$message.success('提交成功')
              this.shenhe_sub();
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 订单审核
    shenhe_sub() {
      let query = {
        id: this.ruleForm.id,
        status: "1",
        remark: this.butongguo,
        field: this.order_audit_name,
      };
      auditOrder(query).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: "提交成功",
            type: "success",
          });
          this.$store.state.tagsView.visitedViews.splice(this.$store.state.tagsView.visitedViews.findIndex(item => item.path === this.$route.path), 1)
          this.$router.go(-1)
        }
      });
    },
    type_change(val) {
      this.ruleForm.modelid = ''
      this.productList_mx = [];
      this.ModelNumberList = [];
      // this.FieldList=[]
      // this.ban_product=[]
      this.get_ModelList(val);
    },
    model_number_id_change(val) {
      this.get_ColorByModelNumberId(val);
      for (let i = 0; i < this.ModelNumberList.length; i++) {
        if (val == this.ModelNumberList[i].id) {
          this.$set(
            this.ruleForm,
            "model_number",
            this.ModelNumberList[i].model_number
          );
          if (this.ModelNumberList[i].pivot.unit_price) {
            this.$set(this.ruleForm, "unit_price", this.ModelNumberList[i].pivot.unit_price);
          }
          this.SpecificationList = this.ModelNumberList[i].specification
        }
      }
      if (this.type == 1) {
        this.get_SemiListByProductId(val);
      }
    },
    specification_change(val) {
      this.SpecificationList.forEach(item => {
        if (val == item.id) {
          if (item.pivot.unit_price) {
            this.$set(this.ruleForm, "unit_price", this.ModelNumberList[i].pivot.unit_price);
          }
        }
      })
    },
    get_ColorByModelNumberId(id) {
      getColorByModelNumberId({ model_number_id: id }).then((res) => {
        if (res.code == 200) {
          this.ruleForm.color_id = res.data;
        }
      });
    },
    get_SpecificationList() {
      getSpecificationList().then((res) => {
        if (res.code == 200) {
          this.SpecificationList = res.data.data;
        }
      });
    },
    numzhu(str) {
      const regex = /\d+/; // 匹配数字的正则表达式
      const result = str.replace(regex, (match) => {
        const number = Number(match); // 将匹配到的数字转换为整数
        const incrementedNumber = number + 1; // 加1
        return incrementedNumber.toString(); // 将结果转换为字符串
      });
      return result;
    },
    set_products(row) {
      let rows = JSON.parse(JSON.stringify(row));
      let serial_number = this.numzhu(rows.serial_number.toString());
      let order_number = this.numzhu(rows.order_number.toString());
      row.serial_number = serial_number;
      row.order_number = order_number;
      this.dataList.push(JSON.parse(JSON.stringify(row)));
    },
    set_product(row) {
      this.ruleForm = row;
    },
    get_ColorList() {
      getColorList({ per_page: 1000 }).then((res) => {
        if (res.code == 200) {
          this.ColorList = res.data.data;
        }
      });
    },
    dels_Order() {
      this.$router.push("/order_goods/order_goods");
    },
    del_Order(id) {
      delOrder({ id }).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功");
          this.$store.state.tagsView.visitedViews.splice(
            this.$store.state.tagsView.visitedViews.findIndex(
              (item) => item.path === this.$route.path
            ),

          );
          this.$router.go(-1);
        }
      });
    },

    // 业务员列表
    getEmpl() {
      getYeWuYuanList().then((res) => {
        if (res.code == 200) {
          this.EmployeeList = res.data;
        }
      });
    },
    yanse_change(val) {
      var list = [];
      for (let i = 0; i < this.ColorList.length; i++) {
        list.push(this.ColorList[i].id);
        if (val == this.ColorList[i].id) {
          this.$set(this.ruleForm, "color", this.ColorList[i].color);
        }
      }
      if (!list.includes(val)) {
        this.create_Color(val);
      }
    },
    create_Color(val) {
      let lists = [];
      let list = [];
      list.push(val);
      lists.push(this.ruleForm.product_id);
      let obj = {
        product_ids: lists,
        color_names: list,
      };
      createColor(obj).then((res) => {
        if (res.code == 200) {
          let lengths = this.ColorList.length;
          this.$set(this.ColorList, lengths, { id: res.data[0], color: val });
          this.get_produccolor(this.ruleForm.product_id);
          let that = this;
          setTimeout(() => {
            that.ruleForm.color_id = res.data[0];
          }, 500);
        }
      });
    },
    guige_change(val) {
      var list = [];
      for (let i = 0; i < this.SpecificationList.length; i++) {
        list.push(this.SpecificationList[i].id);
        if (val == this.SpecificationList[i].id) {
          this.$set(
            this.ruleForm,
            "specification",
            this.SpecificationList[i].specification
          );
        }
      }
      if (!list.includes(val)) {
        this.update_Specification(val);
      }
    },
    product_id_change_1(val) {
      this.ModelNumberList = [];
      // this.get_producModel(val);
      this.ruleForm.model_number_id = "";
      this.productList_mx.forEach(item => {
        if (val == item.id) {
          this.ModelNumberList = item.price
          if (item.product_name == '软床') {
            this.is_addchuangtougui = true
            this.is_addchuangtou = true
            this.is_addchuangbian = true
          }
        }
      })
    },
    auto_maticGenerationOrderNumber() {
      automaticGenerationOrderNumber().then((res) => {
        this.ruleForm.order_number = res.data;
      });
    },
    automatic_GenerationSerialNumber() {
      automaticGenerationSerialNumber().then((res) => {
        this.ruleForm.serial_number = res.data;
      });
    },
    get_produccolor() {
      getProductColorList().then((res) => {
        if (res.code == 200) {
          this.ColorList = res.data;
        }
      });
    },
    get_producModel(id) {
      getModelNumberListByProduct({ product_id: id }).then((res) => {
        if (res.code == 200) {
          this.ModelNumberList = res.data;
        }
      });
    },
    select_goods_shelf(val) {
      this.huojialist.forEach((item) => {
        if (val == item.id) {
          this.$set(this.ruleForm, "goods_shelf", item.goods_shelf);
        }
      });
    },
    direction_change(val) {
      this.directionList.forEach((item) => {
        if (val == item.id) {
          this.$set(this.ruleForm, "direction", item.name);
        }
      });
    },
    account_executive_change(val) {
      this.EmployeeList.forEach((item) => {
        if (val == item.id) {
          this.$set(this.ruleForm, "account_executive", item.company_name);
        }
      });
    },
    customer_change(val) {
      this.CustomerList.forEach((item) => {
        if (val == item.id) {
          this.$set(this.ruleForm, "customer_name", item.customer_name);
        }
      });
    },
    //产品列表
    getproduct() {
      getProductList().then((res) => {
        if (res.code == 200) {
          this.productList = res.data.data;
        }
      });
    },
    //产品列表
    async getproduct_mx(val) {
      var arry = []
      await getProductList({ is_dropdown: 1, modelid: val }).then((res) => {
        if (res.code == 200) {
          this.productList_mx = res.data;
          arry = res.data;
          // this.ruleForm.product_id = res.data[0].id
          if (this.ruleForm.product_id == res.data[0].id && res.data[0].product_name == '软床') {
            this.is_addchuangtougui = true
            this.is_addchuangtou = true
            this.is_addchuangbian = true
          }
        }
      });
      return arry
    },
    get_ProductFieldList(val) {
      getProductFieldList({ modelid: val }).then((res) => {
        if (res.code == 200) {
          this.FieldList = res.data;

          let FieldList_new = [];
          this.FieldList.forEach((item) => {
            if (item.is_default == 2) {
              FieldList_new.push(item);
            }
          });


          if (this.istrue) {
            FieldList_new.forEach(item => {
              if (item.field == 'discount') {
                item.default_value = this.ruleForm.discount
              }
              if (item.field == 'spare_money') {
                item.default_value = this.ruleForm.spare_money
              }
              if (item.field == 'unit_price') {
                item.default_value = this.ruleForm.unit_price
              }
            })
            this.FieldList_new = []
            this.FieldList_new = FieldList_new
            setTimeout(() => {
              this.push_ruleForm()
              this.istrue = false
            }, 2000)
          } else {
            this.FieldList_new = FieldList_new
          }

        }
      });
    },
    // 客户列表
    getCustomer() {
      getCustomerList({ per_page: 99999 }).then((res) => {
        if (res.code == 200) {
          this.CustomerList = res.data.data;
        }
      });
    },
    modelid_change(val) {
      // this.ruleForm.product_id = "";
      this.getproduct_mx(val);
      this.get_ProductFieldList(val);
      // this.automatic_GenerationSerialNumber();
      // this.auto_maticGenerationOrderNumber();

    },
    get_ModelList() {
      let obj = {
        is_dropdown: 1,
        type: this.type,
      };
      getModelList(obj).then((res) => {
        if (res.code == 200) {
          this.ModelList = res.data;
        }
      });
    },
    get_OrderAuditList() {
      getOrderAuditList().then((res) => {
        if (res.code == 200) {
          this.AuditList = res.data.data;
        }
      });
    },

    required(val) {
      for (let i = 0; i < this.FieldList.length; i++) {
        if (this.FieldList[i].field == val && this.FieldList[i].required == 1) {
          return this.FieldList[i].field;
        }
      }
    },
    changeValue() {
      this.$forceUpdate();
    },
    forEachs(val) {
      for (let i = 0; i < this.FieldList.length; i++) {
        if (this.FieldList[i].field == val && this.FieldList[i].show == 1) {
          return true;
        }
      }
    },
  },
};
</script>
<style scoped>
.list_order {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  place-items: left;
}

.list_orders {
  display: grid;
  grid-template-columns: .5fr 1fr 1fr 2fr 1fr 1fr;
  place-items: left;
}


.list_order .lis {
  width: 100%;
}
</style>
